package com.chenjt.jvm.first.four_stack.DynamicLinking;

/**
 * 注释：早期绑定和晚期绑定的例子
 *
 * @author chenjt
 * @date 2025/6/6 14:23
 */
class Animal{
    public void eat(){
        System.out.println("动物进食");
    }
}
interface Huntable{
    public void hunt();
}

class Doc extends Animal implements Huntable{
    public void eat(){
        System.out.println("狗吃骨头");
    }
    public void hunt(){
        System.out.println("狗在捕食");
    }
}

class Cat extends Animal implements Huntable{

    public Cat(){
        super();//表现为：早期绑定
    }

    public Cat(String name){
        this();//表现为：早期绑定
    }

    public void eat(){
        super.eat();
        System.out.println("猫吃鱼");
    }
    public void hunt(){
        System.out.println("猫在捕食");
    }
}

public class AnimalTest {
    public void showAnimal(Animal animal){
        animal.eat();// 表现为：晚期绑定
    }

    public void showHunt(Huntable huntable){
        huntable.hunt();// 表现为：晚期绑定
    }

}
